<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="Content-Language" content="en-us">
	<title>Xtext-Web State Machine Example (Auto-Generator)</title>
	<link rel="stylesheet" type="text/css" href="orion/code_edit/built-codeEdit.css" />
	<link rel="stylesheet" type="text/css" href="xtext/@xtext-version-placeholder@/xtext-orion.css" />
	<link rel="stylesheet" type="text/css" href="style.css" />
	<script src="webjars/requirejs/2.3.7/require.min.js"></script>
	<script type="text/javascript">
		var baseUrl = window.location.pathname;
		var fileIndex = baseUrl.indexOf("orion-statemachine-autogenerate.html");
		if (fileIndex > 0)
			baseUrl = baseUrl.slice(0, fileIndex)
		require.config({
			baseUrl: baseUrl,
			paths: {
				'text': 'webjars/requirejs-text/2.0.15/text',
				'jquery': 'webjars/jquery/3.6.0/jquery.min',
				"xtext/xtext-orion": "xtext/@xtext-version-placeholder@/xtext-orion",
			}
		});
		require(["orion/code_edit/built-codeEdit-amd"], function() {
			require(['xtext/xtext-orion'], function(xtext) {
				xtext.createEditor({syntaxDefinition: "xtext/statemachine-syntax", baseUrl: baseUrl,}).done(function(editorViewer) {
					var xtextServices = editorViewer.xtextServices;
					$('#save-button').click(function() {
						xtextServices.saveResource();
					});
					$('#revert-button').click(function() {
						xtextServices.revertResource();
					});
					xtextServices.successListeners.push(function(serviceType, result) {
						if (serviceType == 'validate' && result.issues.every(function(issue) {issue.severity != 'error'})) {
							// Option 1: use a simple GET request
							$('#generator-result').html('<iframe src="' + location.protocol + '//' + location.host + baseUrl + 'xtext-service/generate?resource=example1.statemachine"></iframe>');
							// Option 2: use the 'generate' function
							xtextServices.generate({artifactId: '/hidden.txt'}).done(function(result) {
								console.log(result);
							});
						}
					});
				});
			});
		});
	</script>
</head>
<body>

<div class="container">
	<div class="xtext-editor"
		data-editor-resource-id="example1.statemachine"
		data-editor-dirty-element="dirty-indicator"
		data-editor-enable-save-action="true"
		data-editor-enable-formatting-action="true"
		data-editor-show-error-dialogs="true"></div>
	<div class="status-wrapper">
		<button id="save-button">Save</button>
		<button id="revert-button">Revert</button>
		<div id="dirty-indicator">modified</div>
		<div id="status">Welcome to Xtext-Web</div>
	</div>
</div>
<div id="generator-result">
</div>

</body>
</html>
